import 'package:car_map/mode/oil_expansionpanle_model.dart';
import 'package:car_map/page/res/gaps.dart';
import 'package:car_map/page/res/styles.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'load_image.dart';

class OilExpansionPanelListWidget extends StatefulWidget{
  @override
  _expansionPanelListState createState()=>_expansionPanelListState();

}

class _expansionPanelListState extends State<OilExpansionPanelListWidget>{

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getsdqytjCountList();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      child: ExpansionpanelWidget(),
    );
  }

  Widget ExpansionpanelWidget(){

    return Container(
      width: double.infinity/2,
      child:  ExpansionPanelList(
        expansionCallback: (expan, isExpanded) {
          setState(() {
            list[expan].isChange = !isExpanded;
          });
        },
        children: list.map((item) {
          return new ExpansionPanel(
            headerBuilder: (context, isExpanded) {
              return getOilItem(item);
            },
            body: Container(
              height: ScreenUtil().setHeight(item.data.length * 200.0),
              child: ListView.builder(
                itemBuilder: (context, index) {
                  return getContentOilItem(item.data[index],item.license);
                },
                itemCount: item.data.length,
              ),
            ),
            isExpanded: item.isChange,
          );
        }).toList(),
      ),
    );
  }

  List<OilExpansionpanleModel> list;

   getsdqytjCountList() {
    list = new List();
    List<ExpansionpanleData> expansionpanleEntityData = new List();
    expansionpanleEntityData..add(new ExpansionpanleData(
     timeDate: '2019-10-31 15:09:33',
      oilType: '92#',
      address: '陕西省西安市雁塔区摩尔中心'
    ))
      ..add(new ExpansionpanleData(
          timeDate: '2019-10-31 11:13:39',
          oilType: '91#',
          address: '陕西省西安市雁塔区科技四路'
      ))
      ..add(new ExpansionpanleData(
          timeDate: '2019-10-31 00:10:43',
          oilType: '92#',
          address: '陕西省西安市雁塔区小寨'
      ));
    list.add(new OilExpansionpanleModel(
        license: '陕A00001', data: expansionpanleEntityData, isChange: false));


  }

  //加油详情item
  Widget getContentOilItem(ExpansionpanleData expansionpanleData,String license){

     return Container(
       alignment: Alignment.center,
       height: ScreenUtil().setHeight(200.0),
       padding: EdgeInsets.only(left: 30.0,right: 10.0,top: 5.0,bottom: 5.0),
       decoration: BoxDecoration(
         color: Colors.black12,
         border: Border.all(
           color: Colors.black12,
           width: 0.5
         )
       ),
       child: Column(
         mainAxisAlignment: MainAxisAlignment.center,
         crossAxisAlignment: CrossAxisAlignment.start,
         children: <Widget>[
           Text(
             '车牌号码: ${license}',style: TextStyles.textDarkGray14,
           ),
       Gaps.vGap5,
           Row(
             mainAxisAlignment: MainAxisAlignment.spaceBetween,
             children: <Widget>[
               Text('时间:${expansionpanleData.timeDate}',style: TextStyles.textDarkGray14,),
               Gaps.vGap5,
               Text('油品型号:${expansionpanleData.oilType}',style: TextStyles.textDarkGray14,),
             ],
           ),
           Gaps.vGap5,
           Text('位置:${expansionpanleData.address}',style: TextStyles.textDarkGray14,)
         ],
       ),
     );
  }

  //加油item
  Widget getOilItem(OilExpansionpanleModel oilExpansionpanleModel){
     return Container(
       child: ListTile(
         title:  Text('${oilExpansionpanleModel.license}', style: TextStyles.textSize16,),
         leading:  LoadAssetImage(
           "statistics/ic_car_no",
           width: ScreenUtil().setWidth(50.0),
           height: ScreenUtil().setHeight(50.0),
         ),
        subtitle: Text('加油:（3）'),
       ),
     );
  }

}